package com.ruoyi.result.report.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.result.report.domain.ResultReport;
import com.ruoyi.result.report.domain.dto.ResultReportDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 新闻报道上传Mapper接口
 *
 * @author ruoyi
 * @date 2025-01-14
 */
@Mapper
public interface ResultReportMapper
{
    /**
     * 查询新闻报道上传
     *
     * @param id 新闻报道上传主键
     * @return 新闻报道上传
     */
    public ResultReport selectResultReportById(Long id);

    /**
     * 查询新闻报道上传列表
     *
     * @param resultReport 新闻报道上传
     * @return 新闻报道上传集合
     */
    public List<ResultReport> selectResultReportList(ResultReportDTO resultReport);

    /**
     * 新增新闻报道上传
     *
     * @param resultReport 新闻报道上传
     * @return 结果
     */
    public int insertResultReport(ResultReport resultReport);

    /**
     * 修改新闻报道上传
     *
     * @param resultReport 新闻报道上传
     * @return 结果
     */
    public int updateResultReport(ResultReport resultReport);

    /**
     * 删除新闻报道上传
     *
     * @param id 新闻报道上传主键
     * @return 结果
     */
    public int deleteResultReportById(Long id);

    /**
     * 批量删除新闻报道上传
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteResultReportByIds(Long[] ids);

    List<ResultReport> selectResultReportByIds(Long[] ids);

    @Select("SELECT COUNT(*) FROM result_report WHERE sync_status = '是' AND is_deleted = 0")
    long selectCount();

    @Select("SELECT YEAR(report_time) as year, COUNT(*) as count FROM result_report " +
            "WHERE is_deleted = 0 " +
            "GROUP BY YEAR(report_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYear();

    @Select("SELECT YEAR(report_time) as year, COUNT(*) as count FROM result_report " +
            "WHERE is_deleted = 0 AND user_id = #{userId} " +
            "GROUP BY YEAR(report_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYearAndUserId(@Param("userId") Long userId);
}
